<?php

namespace plugin\cms\app\controller\uc;

use core\controller\UcBase;
use Exception;
use plugin\cms\app\bll\Content as BllContent;
use plugin\cms\app\bll\PointsExchange as BllPointsExchange;

class PointsExchange extends UcBase
{
    /**
     * 积分兑换
     *
     * @return mixed
     */
    public function exchange()
    {

        try {

            $postdata = request()->post();
            $bllContent = new BllContent();
            $content =  $bllContent->find($postdata['id'], $postdata['cid'], $postdata['siteid']);


            $data = [
                'cid'       => $postdata['cid'],
                'siteid'    => $postdata['siteid'],
                'contentid' => $postdata['id'],
                'uid'       => request()->userinfo['id'],
                'point'     => $content['points'],
            ];
            $bllPointsExchange = new  BllPointsExchange();
            $bllPointsExchange->add(
                $postdata['id'],
                $postdata['cid'],
                $postdata['siteid'],
                request()->userinfo['id']
            ); //兑换
        } catch (Exception $ex) {
            return $this->error($ex->getMessage());
        }
        return $this->success();
    }
}
